package adapters;

import java.util.ArrayList;

import pkg.inno.fileshare.R;

import model.MenuItem;
import model.MenuSubItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter 
{
	private Context _context;
	private ArrayList<MenuItem> _menuItemList;
	
	public ExpandableListAdapter(Context context,ArrayList<MenuItem> menuItemList)
	{
		this._context=context;
		this._menuItemList=menuItemList;
	}
	
	
	public Object getChild(int arg0, int arg1) 
	{
		ArrayList<MenuSubItem> subItemList=_menuItemList.get(arg0).get_childList();
		return subItemList.get(arg1);
	}

	public long getChildId(int arg0, int arg1) 
	{
		return arg1;
	}

	public View getChildView(int arg0, int arg1, boolean arg2, View arg3,ViewGroup arg4) 
	{
		MenuSubItem subItem=(MenuSubItem)getChild(arg0, arg1);
		
		if (arg3==null) 
		{
			LayoutInflater infalInflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			arg3 = infalInflater.inflate(R.layout.child_row, null);
		}
		
		TextView sequence = (TextView) arg3.findViewById(R.id.sequence);
		sequence.setText(subItem.get_parentMenuId()+ ") ");
		
		TextView childItem = (TextView) arg3.findViewById(R.id.childItem);
		childItem.setText(subItem.get_menuName().trim());
		  
		return arg3;
	}

	public int getChildrenCount(int arg0) 
	{
		return _menuItemList.get(arg0).get_childList().size();
	}

	public Object getGroup(int arg0) 
	{
		return _menuItemList.get(arg0);
	}

	public int getGroupCount() 
	{
		return _menuItemList.size();
	}

	public long getGroupId(int arg0) 
	{
		return arg0;
	}

	public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) 
	{
		MenuItem headerInfo = (MenuItem) getGroup(arg0);
		if (arg2 == null) 
		{
			LayoutInflater inf = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			arg2 = inf.inflate(R.layout.group_heading, null);
		}
	   
		TextView heading = (TextView) arg2.findViewById(R.id.heading);
		heading.setText(headerInfo.get_menuName().trim());
	   
		return arg2;
	}

	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return true;
	}

	public boolean isChildSelectable(int arg0, int arg1) 
	{
		// TODO Auto-generated method stub
		return true;
	}

}
